import {ITodoData} from './data'
import ToDom from './domProcessing'
export default class ProcessingData extends ToDom{
    todolist:ITodoData[]
    constructor(list:ITodoData[],warpper:HTMLElement){
        super(warpper)
        this.todolist = list
    }
    //删除
    removeData(id:number,dom:HTMLElement):void{
       let i = this.todolist.findIndex((item:ITodoData)=>{
           return item.id === id
       })
       this.todolist.splice(i,1)
       this.removeDom(dom)
    }
    //修改
    changeData(id:number,dom:HTMLElement):void{
        this.todolist.map((item:ITodoData)=>{
            if(item.id === id){
                item.completed = !item.completed
            }
            return item
        })
        this.changeDom(dom)
    }
    //添加数据
    addData(todo:ITodoData):undefined|number{
        const flag = this.todolist.some((item:ITodoData)=> item.content === todo.content)
        if(!flag){
            this.todolist.push(todo)
            return
        }
        return 0
    }
}